package com.atguigu.srb.core.controller.api;


import com.atguigu.common.result.R;
import com.atguigu.common.utils.JwtUtils;
import com.atguigu.srb.core.pojo.vo.BorrowerVO;
import com.atguigu.srb.core.service.BorrowerService;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 * <p>
 * 借款人 前端控制器
 * </p>
 *
 * @author ${author}
 * @since 2022-09-13
 */
@RestController
@RequestMapping("/api/core/borrower")
public class ApiBorrowerController {

    @Resource
    private BorrowerService borrowerService;
    @ApiOperation("获取借款人认证状态")
    @GetMapping("/getBorrowerStatusByUserId")
    public R getBorrowerStatusByUserId(HttpServletRequest request){
        String userId = request.getHeader("userId");
      Integer borrowerStatus = borrowerService.getBorrowerStatusByUserId(userId);
      return R.ok().data("borrowerStatus",borrowerStatus);
    }
    @ApiOperation("保存贷款信息认证")
    @PostMapping("/auth/save")
    public R saveBorrower(@RequestBody BorrowerVO borrowerVO,
                          HttpServletRequest request) {
        String token = request.getHeader("token");
        Long userId = JwtUtils.getUserId(token);
        borrowerService.saveBorrower(borrowerVO,userId);
        return R.ok();
    }

}

